package com.lemon.smartsafetynew.ui.activity.record;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.ApplicationInfo;
import com.lemon.smartsafety.data.app.DataUtil;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.entity.record.FunctionVo;
import com.lemon.smartsafetynew.ui.adapter.record.RecordFunctionGridAdapter;
import com.lemon.smartsafetynew.ui.fragment.record.RecordCompanyPeopleActivity;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import java.util.List;

import butterknife.Bind;

/**
 * 企业的一企一档具体查看页
 * Created by Andrew on 2018/1/22.
 */

public class RecordFunctionActivity extends SwipeBackActivity
        implements RecyclerTClickListener<FunctionVo> {

    @Bind(R.id.company_name_tv)
    TextView companyNameTv;
    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;

    private static MeCompanyVo companyVo;

    private RecordFunctionGridAdapter mRecordFunctionGridAdapter;

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }
        }
    }

    @Override
    protected void initTitle() {
        this.setBarTitle(getString(R.string.work_options_main_1));
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(RecordFunctionActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_function;
    }

    @Override
    protected void initViews() {
        super.initViews();

        List<FunctionVo> functionVoList = DataUtil.getFunctionList();
        mRecordFunctionGridAdapter = new RecordFunctionGridAdapter(functionVoList, this);
        GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(mRecordFunctionGridAdapter);

        companyNameTv.setText(CommonUtil.avoidNullString(companyVo.getCompany_name()));

    }

    @Override
    public void onItemClick(FunctionVo data, int position) {

        Bundle bundle = new Bundle();
        companyVo.setIfShowReturn(false);

        if (ApplicationInfo.RecordFunctionEnum.LOACL_PATROL_TYPE.equals(data.getRecordFunctionEnum())) {
            // 检查点位
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordPatrolActivity.class);

        } else if (ApplicationInfo.RecordFunctionEnum.LOACL_HIDDEN_TYPE.equals(data.getRecordFunctionEnum())) {
            // 隐患记录
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordHiddenActivity.class);

        } else if (ApplicationInfo.RecordFunctionEnum.WEB_NORMAL_INFO_TYPE.equals(data.getRecordFunctionEnum())) {
            // 基本信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordBaseInfoActivity.class);

        } else if (ApplicationInfo.RecordFunctionEnum.WEB_PERSON_TYPE.equals(data.getRecordFunctionEnum())) {
            // 企业人员
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordCompanyPeopleActivity.class);

        } else if (ApplicationInfo.RecordFunctionEnum.WEB_MAJOR_HAZARD_TYPE.equals(data.getRecordFunctionEnum())) {
            // 重大危险源
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, MajorHazardNewActivity.class);
            // TODO 看是否有需要使用新的重大危险源
        } else if (ApplicationInfo.RecordFunctionEnum.WEB_SPECIAL_EQUIPMENT_TYPE.equals(data.getRecordFunctionEnum())) {
            // 特种设备
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordEquipmentActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.WEB_MATERIALS_INFO_TYPE.equals(data.getRecordFunctionEnum())) {
            // 物料信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, MaterielActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.WEB_TANKS_INFO_TYPE.equals(data.getRecordFunctionEnum())) {
            // 储罐信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordTankActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.WEB_DUST_INFO_TYPE.equals(data.getRecordFunctionEnum())) {
            // 粉尘信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, DustActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.WEB_CONFINED_SPACE_TYPE.equals(data.getRecordFunctionEnum())) {
            // 受限空间
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordSpaceActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_ELECTRICAL_TYPE.equals(data.getRecordFunctionEnum())) {
            // 配电箱信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, SwitchBoxActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_AIR_TYPE.equals(data.getRecordFunctionEnum())) {
            // 可燃气体
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, AirActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_HIGH_DANGER_TYPE.equals(data.getRecordFunctionEnum())) {
            // 高危工艺
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordHighDangerActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_METALLURGY_TYPE.equals(data.getRecordFunctionEnum())) {
            // 冶金信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordMetalActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_AMMONIA_TYPE.equals(data.getRecordFunctionEnum())) {
            // 液氨信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordAmmoniaActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_OCCUPATIONA_TYPE.equals(data.getRecordFunctionEnum())) {
            // 职业病危害信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordOccupationActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_EMERGENCY_TYPE.equals(data.getRecordFunctionEnum())) {
            // 应急物资
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordEmergencyActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_SPECISL_TASK_TYPE.equals(data.getRecordFunctionEnum())) {
            // 特种作业操作证人员
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordCertificateActivity.class);
        } else if (ApplicationInfo.RecordFunctionEnum.LOCAL_COMPANY_TRAINING_TYPE.equals(data.getRecordFunctionEnum())) {
            // 企业安全培训信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordSafeTrainingActivity.class);
        }else if (ApplicationInfo.RecordFunctionEnum.LOCAL_EMERGENCY_PLAN_TYPE.equals(data.getRecordFunctionEnum())) {
            // 企业安全培训信息
            bundle.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);
            UIHelper.showActivity(RecordFunctionActivity.this, bundle, RecordEmergencyPlanActivity.class);
        }

    }
}
